package activities.project3.group3.s12cs342;

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import tools.Project3.Group3.s12cs342.AsyncAuth;
import tools.Project3.Group3.s12cs342.AsyncDownload;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class AuthenticateActivity extends Activity {
EditText un,pw;
TextView error;
Button ok;



/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	new AsyncDownload(AuthenticateActivity.this,"", getApplicationContext()).execute();
	setContentView(R.layout.login);
	un=(EditText)findViewById(R.id.usernameField);
		pw = (EditText) findViewById(R.id.passwordField);
		ok = (Button) findViewById(R.id.bLogin);
		error = (TextView) findViewById(R.id.errorLbl);
		 
		 
		ok.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
				postParameters.add(new BasicNameValuePair("username", un
						.getText().toString()));
				postParameters.add(new BasicNameValuePair("password", pw
						.getText().toString()));
				
				SharedPreferences app_preferences = PreferenceManager
						.getDefaultSharedPreferences(AuthenticateActivity.this);

				SharedPreferences.Editor editor = app_preferences.edit();
				editor.putString("name", un.getText().toString());
				editor.putString("pass", pw.getText().toString());
				editor.commit();

				

				new
				 AsyncAuth(AuthenticateActivity.this,"http://cs346.cs.uwosh.edu/students/preram47/login.php",
				 postParameters, getApplicationContext()).execute();
			
			}
		});
	}
}